package handler

import (
	"dou/api/request"
	"dou/internal/dao"
	"dou/internal/model"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Login(c *gin.Context) {

	c.JSON(http.StatusOK, gin.H{
		"message": "pong",
	})
}

func FindVideo(c *gin.Context) {
	var req request.FindByVideo

	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    1000,
			"message": "取值失败",
			"data":    nil,
		})
	}
	var data model.Video
	if !dao.GetOneById(req.Id, &data) {
		c.JSON(http.StatusOK, gin.H{
			"code":    1000,
			"message": "查询失败",
			"data":    nil,
		})
	}

	c.JSON(http.StatusOK, gin.H{
		"code":    0,
		"message": "查询成功",
		"data":    data,
	})
}

func FindNameVideo(c *gin.Context) {
	var req request.FindVideo

	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    1000,
			"message": "取值失败",
			"data":    nil,
		})
	}
	var data model.Video
	if !dao.GetOneByFields(&model.Video{Name: req.Name}, &data) {
		c.JSON(http.StatusOK, gin.H{
			"code":    1000,
			"message": "查询失败",
			"data":    nil,
		})
	}

	c.JSON(http.StatusOK, gin.H{
		"code":    0,
		"message": "查询成功",
		"data":    data,
	})
}
